/**
* Handlers for MINUS and PLUS icons to decrease or increase the values in each sizes.
*/
function calculate(direction, current_value)
{
	if(!current_value || 'undefined'==current_value || isNaN(current_value)) current_value=0;
	current_value = parseInt(current_value);
	if(direction=='+')
	{
		return current_value+1;
	}
	else if(direction=='-')
	{
		if(current_value>0)
			return current_value-1;
	}
	return current_value;
}
function process_pixels(field, direction)
{
	var x = document.getElementsByTagName('input');
	if(x.length <= 1) return false;
	for(i=0; i<x.length; ++i)
	{
		if(x[i].className!='short-'+field) continue;
		x[i].value = calculate(direction, x[i].value);
	}
	return false;
}
function pixels_minus_x()
{
	return process_pixels('x', '-');
}
function pixels_plus_x()
{
	return process_pixels('x', '+');
}
function pixels_minus_y()
{
	return process_pixels('y', '-');
}
function pixels_plus_y()
{
	return process_pixels('y', '+');
}

document.getElementById('pixels-minus-x').onclick = pixels_minus_x;
document.getElementById('pixels-plus-x').onclick = pixels_plus_x;
document.getElementById('pixels-minus-y').onclick = pixels_minus_y;
document.getElementById('pixels-plus-y').onclick = pixels_plus_y;

/*
document.getElementById('pixels-minus-x').onmouseover = pixels_minus_x;
document.getElementById('pixels-plus-x').onmouseover = pixels_plus_x;
document.getElementById('pixels-minus-y').onmouseover = pixels_minus_y;
document.getElementById('pixels-plus-y').onmouseover = pixels_plus_y;

document.getElementById('pixels-minus-x').onmouseout = clearInterval;
document.getElementById('pixels-plus-x').onmouseout = clearInterval;
document.getElementById('pixels-minus-y').onmouseout = clearInterval;
document.getElementById('pixels-plus-y').onmouseout = clearInterval;
*/

/**
* Set the ID
*/
function _setnow()
{
	var field = this.id[0];
	var id = parseInt(this.id.substring(1));
	var current_value = parseInt(document.getElementById(''+field+field+id).value);
	//alert('setting up: '+this.id+": "+field+"id: "+id+", current value: "+current_value);
	if(window.confirm('Reset all '+field+' values to: '+current_value+'?'))
	{
		var x = document.getElementsByTagName('input');
		if(x.length <= 1) return false;
		for(i=0; i<x.length; ++i)
		{
			if(x[i].className!='short-'+(field.toLowerCase())) continue;
			//x[i].value = calculate(direction, x[i].value);
			//alert(x[i].value);
			x[i].value = current_value;
		}
	}
	return false;
}
function setnow()
{
	var setnow = document.getElementsByTagName('a');
	for(i=0; i<setnow.length; ++i)
	{
		if(setnow[i].className=='setnow')
		{
			setnow[i].onclick = _setnow;
		}
	}
}
setnow();

/**
* Select or deselect all visible entities
* Installs the "check/uncheck all" handler
*/
function _select_deselect_all_visible_thumbnails()
{
	checker = (this.checked==true);
	var lists = document.getElementsByTagName('input');
	if(lists.length <= 1) return false;
	for(var i=0; i<lists.length; ++i)
	{
		if(lists[i].type=='checkbox' && lists[i].className=='no-thumbnail')
		{
			 lists[i].checked = checker;
		}
	}
	return true;
}
function handle_select_all_thumbnails()
{
	if(document.getElementById('removeall'))
	{
		document.getElementById('removeall').onclick = _select_deselect_all_visible_thumbnails;
	}
}
handle_select_all_thumbnails();